import scrapy


class ChanspiderSpider(scrapy.Spider):
    name = 'chanspider'
    allowed_domains = ['4chan.org']
    start_urls = []

    def parse(self, response):
        thread_number = response.url.split('/')[-1]
        name = response.css('span.name::text').get()
        subject = response.css('span.subject::text').get()
        hrefs = [{"filename": h.split('/')[-1], "link": f'https:{h}'}
                 for h in response.css('a.fileThumb::attr(href)').getall()]

        yield {
            "folder": f'{thread_number}_{name}_{subject}',
            "hrefs": hrefs
        }
